<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>留言列表-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/resource/backend/css/font.css">
    <link rel="stylesheet" href="/resource/backend/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="weadmin-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">留言管理</a>
        <a>
          <cite>留言列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe669;</i></a>
</div>
<div class="weadmin-body">
    <div class="weadmin-block">
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <span style="color:#009688;font-weight: bold;display: inline-block;width: 70%;text-align: center;">当留言者状态为已读时，说明当前留言已经受理，该电话号码可以提交新留言，否则，该电话号码无法提交新留言。</span>
        <span class="fr" style="line-height:40px">共有数据：${ .list.Total }$ 条</span>
    </div>
    <style>
        .layui-table th {
            min-width: 60px;
        }
    </style>
    <table class="layui-table layui-form">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                        class="layui-icon">&#xe605;</i></div>
            </th>
            <th>ID</th>
            <th>姓名</th>
            <th style="min-width: 100px;">电话</th>
            <th>留言内容</th>
            <th style="min-width: 140px;">留言时间</th>
            <th>来源</th>
            <th style="min-width: 100px;">留言者IP</th>
            <th>IP归属地</th>
            <th>状态</th>
        </thead>
        <tbody>
        ${if gt .list.Total 0}$
        ${range $key, $item := .list.List }$
        <tr>
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='${ $item.Id }$'><i
                        class="layui-icon">&#xe605;</i></div>
            </td>
            <td>${ $item.Id }$</td>
            <td>${ $item.Name }$</td>
            <td>${ $item.Tel }$</td>
            <td>${ $item.Content }$</td>
            <td>${ $item.CreatedAt }$</td>
            <td>${ $item.FromDesc }$</td>
            <td>${ $item.Ip }$</td>
            <td>${ $item.Address }$</td>
            <td>
                <input type="checkbox" name="status" lay-skin="switch" lay-filter="status" lay-text="已读|未读"
                       value="${ $item.Id }$" ${if eq $item.Status 1 }$checked${end}$>
            </td>
        </tr>
        ${end}$
        ${else}$
        <tr>
            <td align="center" colspan="100">暂无数据</td>
        </tr>
        ${end}$
        </tbody>
    </table>
    <div class="page">
        <ul class="pagination">
            ${.pageInfo}$
        </ul>
    </div>
</div>
<script src="/resource/backend/lib/layui/layui.js" charset="utf-8"></script>
<script>
    layui.extend({
        admin: '{/}../../resource/backend/js/admin'
    });
    layui.use(['laydate', 'jquery', 'admin', 'form'], function () {
        var laydate = layui.laydate,
            $ = layui.jquery,
            form = layui.form,
            admin = layui.admin;

        /*修改启用状态*/
        form.on('switch(status)', function (data) {
            //console.log(data.elem); //得到checkbox原始DOM对象
            //console.log(data.elem.checked); //开关是否开启，true或者false
            //console.log(data.value); //开关value值，也可以通过data.elem.value得到
            //console.log(data.othis); //得到美化后的DOM对象
            $.post('${ backend_api_url `/guestbook/status` }$', {'id': data.value}, function (res) {
                if (res.code === 0) {
                    layer.msg(res.message, {icon: 6, time: 1000}, function () {
                        //这里成功不刷新，失败刷新，列表有按状态进行排序
                    });
                } else {
                    //操作失败
                    layer.msg(res.message, {icon: 5, time: 2000}, function () {
                        self.location.reload();
                    });
                }
            });
        });
        /*删除全部*/
        window.delAll = function () {
            var data = tableCheck.getData();
            if (data.length === 0) {
                layer.msg('请选择要删除的留言', {
                    anim: 6
                });
                return false;
            }
            layer.confirm('确认要删除ID(' + data + ')吗？', function (index) {
                $.post('${ backend_api_url `/guestbook/batch_delete` }$', {'ids': data}, function (res) {
                    if (res.code === 0) {
                        layer.msg(res.message, {
                            icon: 6,
                            time: 1000
                        }, function () {
                            self.location.reload();
                        });
                    } else {
                        layer.msg(res.message, {
                            icon: 5,
                            time: 2000
                        });
                    }
                });
            });
        }
    });
</script>
</body>

</html>